<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Search extends CI_Controller {

	// 
	//  search.php
	//  phpweb
	//  
	//  Created by WillLee on 2011-07-10.
	//  Copyright 2011 lishuzu. All rights reserved.
	// 
	function __construct()
	{
		parent::__construct();
 		$this->load->model('common/security_model');
		if($this->security_model->isLogin() === FALSE){
			showmessage('请登录', 'login', 2);
		}
 		$this->load->model('search_model');
	}
	
	public function index()
	{
		$data = array();
		$searchkey = $this->input->get('searchkey')? stripsearchkey($this->input->get('searchkey', true)) :'';
		$searchtype = $this->input->get('searchtype')? stripsearchkey($this->input->get('searchtype', true)) :'';
		
		if (!in_array($searchtype, array('all', 'work', 'user', 'worktag', 'tagid'))) {
			$searchtype = 'work';
		}else{
			$searchtype= $searchtype;
		}
		
		if ($searchkey && $searchtype) {
			//调用相应处理方法。
			$data = $this->search_model->{'get_'.$searchtype}($searchkey);
		}

		//加载tag缓存
		if (in_array($searchtype, array('worktag', 'tagid'))) {
			// 得到tag缓存 定时更新
			$data['taglist'] = $this->tag_model->get_cache(1);
			$searchkey = '';
		}
		
		//激活tab
		$data['actives'] = array($searchtype=> ' class="active"');
		//搜索字 searchkey
		$data['searchkey'] = $searchkey;
		//搜索字 searchtype
		$data['searchtype'] = $searchtype;
		
		$this->load->template('search_'.$searchtype.'_tpl', $data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */